<?php
/**
 * Description:
 * Author: hezhizheng
 * Date: 2018/11/14
 * Time: 14:41
 * Created by Created by Panxsoft.
 */

namespace App\Models\Products;

use App\Models\Concerns\ModelMemorable;
use App\Models\Options\Option;
use App\Models\Options\OptionDescription;
use App\Services\Locale\Language;
use App\Services\MobileApp\AppEnv;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * 产品选项
 *
 * @mixin Builder
 * @property int product_option_id
 * @property Collection|ProductOptionValue[] productOptionValues
 * @property Option option
 */
class ProductOption extends Model
{
    use ModelMemorable;

    protected $guarded = [];

    protected $table = 'product_option';

    protected $primaryKey = 'product_option_id';

    public function optionDescription()
    {
        return $this->hasOne(OptionDescription::class, 'option_id', 'option_id')
            ->where('language_id', AppEnv::languageId());
    }

    public function productOptionValues()
    {
        return $this->hasMany(ProductOptionValue::class, 'product_option_id', 'product_option_id');
    }

    public function option()
    {
        return $this->belongsTo(Option::class,'option_id','option_id');
    }
}